﻿//提示信息插件
$.extend({
    tip: function (options) {
        var cbk = function () { }
        var defaults = {
            width: "100px",
            target: $("body"),
            fadetime: 300,
            staytime: 200,
            text: "",
            callback: cbk
        }

        var options = $.extend(defaults, options);

        var $tip, $limg, $content, $rimg;
        var left, top, right, bottom;
        var $target = options.target;//$(options.target) || $("#" + options.target) || $("." + options.target) || options.target;
        $limg = $("<div class='tip_img'><img src='../../images/tips/left_bg.png' /></div>");
        $content = $("<div class='tip_content'>" + options.text + "</div>").css("width", options.width);;
        $rimg = $("<div class='tip_img'><img src='../../images/tips/right_bg.png' /></div>");
        $tip = $("<div class='tip_tip'></div>").append($limg).append($content).append($rimg).css("width", (Number(options.width.slice(0, options.width.indexOf("px"))) + 34) + "px");
        $target.append($tip);
        var tw = $target.width(),
            th = $target.height(),
            tipw = $tip.width(),
            tiph = $tip.height();

        left = (tw - tipw) / 2 + "px";
        top = (th - tiph) / 2 + "px";
        $tip.css({ left: left, top: top });
        $tip.fadeToggle(options.fadetime, function () {
            setTimeout(function () {
                $tip.fadeToggle(options.fadetime, options.callback);
            }, options.staytime);
        });
    }
});